package redis

// 集合命令

func SAdd(key string, members ...interface{}) (int, error) {
	args := make([]interface{}, 0, len(members)+1)
	args = append(args, key)
	args = append(args, members...)

	return insRedis.Int("SADD", args...)
}

func SCard(key string) (int, error) {
	return insRedis.Int("SCARD", key)
}

func SMembers(key string) ([]string, error) {
	return insRedis.Strings("SMEMBERS", key)
}

func SIsMember(key, member string) (int, error) {
	return insRedis.Int("SISMEMBER", key, member)
}

func SRem(key string, members ...interface{}) (int, error) {
	args := make([]interface{}, 0, len(members)+1)
	args = append(args, key)
	args = append(args, members...)

	return insRedis.Int("SREM", args...)
}

func SPop(key string) (string, error) {
	return insRedis.String("SPOP", key)
}

func SRandMember(key string, count int) ([]string, error) {
	return insRedis.Strings("SRANDMEMBER", key, count)
}

func SMove(source, destination, member string) (int, error) {
	return insRedis.Int("SMOVE", source, destination, member)
}

func SInter(keys ...interface{}) ([]string, error) {
	return insRedis.Strings("SINTER", keys...)
}

func SInterStore(destination string, keys ...interface{}) (int, error) {
	args := make([]interface{}, 0, len(keys)+1)
	args = append(args, destination)
	args = append(args, keys...)

	return insRedis.Int("SINTERSTORE", args...)
}

func SDiff(keys ...interface{}) ([]string, error) {
	return insRedis.Strings("SDIFF", keys...)
}

func SDiffStore(destination string, keys ...interface{}) (int, error) {
	args := make([]interface{}, 0, len(keys)+1)
	args = append(args, destination)
	args = append(args, keys...)

	return insRedis.Int("SDIFFSTORE", args...)
}

func SUnion(keys ...interface{}) ([]string, error) {
	return insRedis.Strings("SUNION", keys...)
}

func SUnionStore(destination string, keys ...interface{}) (int, error) {
	args := make([]interface{}, 0, len(keys)+1)
	args = append(args, destination)
	args = append(args, keys...)

	return insRedis.Int("SUNIONSTORE", args...)
}
